package io.jee.runshan.utils;

import java.util.Random;

import org.apache.commons.codec.digest.DigestUtils;

public class PasswordEncoder {

	public static String encode(String password, String salt) {
		return DigestUtils.md5Hex(DigestUtils.md5Hex(password) + salt);
	}

	public static String getSalt(int digit) {
		String base = "abcdefghijklmnopqrstuvwxyz0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < digit; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString().toUpperCase();
	}

}
